package com.fredia.terp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fredia.terp.security.xss.XssStringJsonSerializer;

/**
 * Filter相关配置
 * @author : wangyong
 * @since : 2017年6月22日
 * @version : v0.0.1
 */
@Configuration
public class FilterConfig {
	
	/**
	 * xss 过滤器
	 * @param builder
	 * @return
	 * @author : wangyong	
	 * @since : 2017年6月22日
	 */
	@Bean
	@Primary
	public ObjectMapper xssObjectMapper(Jackson2ObjectMapperBuilder builder) {
		// 解析器
		ObjectMapper objectMapper = builder.createXmlMapper(false).build();
		// 注册xss解析器
		SimpleModule xssModule = new SimpleModule("XssStringJsonSerializer");
		xssModule.addSerializer(new XssStringJsonSerializer());
		objectMapper.registerModule(xssModule);
		// 返回
		return objectMapper;
	}
}
